﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using WLWeb.PulbicClass;

namespace WLWeb.UC
{
    public partial class CreateWebLeft : System.Web.UI.UserControl
    {
        /// <summary>
        /// 组别
        /// </summary>
        public string Acticle
        {
            get;
            set;
        }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        {
            get;
            set;
        }
        BLL.wlBLL.Acticle act = new BLL.wlBLL.Acticle();
        BLL.wlBLL.BLL_WebExample example = new BLL.wlBLL.BLL_WebExample();
        WLong.BLL.Category bllcate = new WLong.BLL.Category();
        protected void Page_Load(object sender, EventArgs e)
        {
            GetTaoCanInfo();
        }
        protected void GetTaoCanInfo()
        {
            if (Acticle != null && Acticle != "")
            {
                GetShowDiv(Acticle);
                //if (Acticle == "TaoCan")                         //显示套餐页信息    CreateTaoCan.aspx
                if(Webpublic.IsGroupName(Acticle,1))
                {
                    lblTitle.Text = Title;
                    //string Group = Acticle;
                    DataTable dttaocan = act.GetbllTaoCanInfo(Acticle);
                    if (dttaocan != null && dttaocan.Rows.Count > 0)
                    {
                        repMenuShow1.DataSource = GetDtPublic(dttaocan);
                        repMenuShow1.DataBind();
                    }
                }
                else if (Webpublic.IsGroupName(Acticle, 6))                       //技术文章            Support.aspx
                {
                    lblTitle.Text = Title;
                    DataTable dtit = act.GetSuportCategory(Acticle);
                    if (dtit != null && dtit.Rows.Count > 0)
                    {
                        repMenuShow1.DataSource = GetDtPublic(dtit);
                        repMenuShow1.DataBind();
                    }
                }
                else if (Webpublic.IsGroupName(Acticle,8))                                        //最后一页关于工作室地信息
                {
                    lblTitle.Text = Title;
                    DataTable dtit = act.GetSuportCategory(Acticle);
                    if (dtit != null && dtit.Rows.Count > 0)
                    {
                        repMenuShow1.DataSource = GetDtPublic(dtit);
                        repMenuShow1.DataBind();
                    }
                }
                else if (Webpublic.IsGroupName(Acticle,4))                                        //产品服务
                {
                    lblTitle.Text = Title;
                    DataTable dtit = act.GetSuportCategory(Acticle);
                    if (dtit != null && dtit.Rows.Count > 0)
                    {
                        repMenuShow1.DataSource = GetDtPublic(dtit);
                        repMenuShow1.DataBind();
                    }
                }
                else if (Webpublic.IsGroupName(Acticle,5))                                        //解决方案
                {
                    lblTitle.Text = Title;
                    DataTable dtit = act.GetSuportCategory(Acticle);
                    if (dtit != null && dtit.Rows.Count > 0)
                    {
                        repMenuShow1.DataSource = GetDtPublic(dtit);
                        repMenuShow1.DataBind();
                    }
                }
                else if (Webpublic.IsGroupName(Acticle,2))                                        //新闻
                {
                    lblTitle.Text = Title;
                    DataTable dtit = act.GetSuportCategory(Acticle);
                    if (dtit != null && dtit.Rows.Count > 0)
                    {
                        repMenuShow1.DataSource = GetDtPublic(dtit);
                        repMenuShow1.DataBind();
                    }
                }
                else if (Webpublic.IsGroupName(Acticle,3))                                        //签约
                {
                    lblTitle.Text = Title;
                    DataTable dtit = act.GetSuportCategory(Acticle);
                    if (dtit != null && dtit.Rows.Count > 0)
                    {
                        repMenuShow1.DataSource = GetDtPublic(dtit);
                        repMenuShow1.DataBind();
                    }
                }
                else if (Webpublic.IsGroupName(Acticle,7))                                         //商品实例页
                {
                    lblTitle.Text = Title;
                    DataSet ds= bllcate.GetList(" Grade=0 and IsDisplay=0 and Disabled=0"); //example.GetWebExampleInfo(new Hashtable() { });
                    if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        DataTable dtexample = ds.Tables[0];
                        if (dtexample != null && dtexample.Rows.Count > 0)
                        {
                            repMenuShow2.DataSource = dtexample;//GetDtPublic(dtexample);
                            repMenuShow2.DataBind();
                        }
                    }
                }
            }
            else
            {
                lblTitle.Text = Title;
                GetShowDiv("");
            }
        }
        /// <summary>
        /// 获得Url
        /// </summary>
        /// <param name="Group"></param>
        /// <param name="ArticleId"></param>
        /// <returns></returns>
        protected string GetUrl(string Group, string ArticleId, string CategoryID)
        {   
            if (Webpublic.IsGroupName(Group,1))
            {
                return "../Common/CreateTaoCan.aspx?ArticleInfomationID=" + ArticleId;
            }
            else if (Webpublic.IsGroupName(Group,6))
            {
                return "../Common/Support.aspx?OtherCategoryID=" + CategoryID;
            }
            else if (Webpublic.IsGroupName(Group,8))
            {
                return "../Common/About.aspx?ArticleInfomationID=" + CategoryID;
            }
            else if (Webpublic.IsGroupName(Group,4))
            {
                return "../Common/Service.aspx?OtherCategoryID=" + CategoryID;
            }
            else if (Webpublic.IsGroupName(Group,2))
            {
                return "../Common/News.aspx?OtherCategoryID=" + CategoryID;
            }
            else if (Webpublic.IsGroupName(Group,5))
            {
                return "../Common/Solution.aspx?OtherCategoryID=" + CategoryID;
            }
            else if (Webpublic.IsGroupName(Group,3))
            {
                return "../Common/QianYue.aspx?OtherCategoryID=" + CategoryID;
            }
            return "";
        }

        
        /// <summary>
        /// 显示和隐藏
        /// </summary>
        protected void GetShowDiv(string Acticle)
        {
            if (Webpublic.IsGroupName(Acticle, 1) == true || Webpublic.IsGroupName(Acticle, 6) == true || Acticle == "" || Webpublic.IsGroupName(Acticle, 8) == true || Webpublic.IsGroupName(Acticle, 4) == true || Webpublic.IsGroupName(Acticle, 2) == true || Webpublic.IsGroupName(Acticle, 5) == true || Webpublic.IsGroupName(Acticle,3) == true)                         //显示套餐页信息
            {
                div1.Visible = true;
            }
            else
            {   
                div2.Visible = true;
            }
        }

        /// <summary>
        /// 获取统一的表
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected DataTable GetDtPublic(DataTable dt)               
        {
            DataTable dtable = new DataTable();
            dtable.Columns.Add("OtherCategoryID", typeof(Guid));                //分类ID
            dtable.Columns.Add("OtherCategoryName", typeof(string));            //分类名称
            dtable.Columns.Add("OtherCategoryGroup", typeof(string));           //分类组别
            dtable.Columns.Add("ArticleInfomationID", typeof(string));          //文章ID
            dtable.Columns.Add("ArticleTitle", typeof(string));          //文章Name
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dtable.NewRow();
                    if (dt.Columns.Contains("OtherCategoryID"))
                    {
                        dr["OtherCategoryID"] = dt.Rows[i]["OtherCategoryID"].ToString();
                    }
                    if (dt.Columns.Contains("OtherCategoryName"))
                    {
                        dr["OtherCategoryName"] = dt.Rows[i]["OtherCategoryName"].ToString();
                    }
                    if (dt.Columns.Contains("OtherCategoryGroup"))
                    {
                        dr["OtherCategoryGroup"] = dt.Rows[i]["OtherCategoryGroup"].ToString();
                    }
                    if (dt.Columns.Contains("ArticleInfomationID"))
                    {
                        dr["ArticleInfomationID"] = dt.Rows[i]["ArticleInfomationID"].ToString();
                    }
                    if (dt.Columns.Contains("ArticleTitle"))
                    {
                        dr["ArticleTitle"] = dt.Rows[i]["ArticleTitle"].ToString();
                    }
                    dtable.Rows.Add(dr);
                }
            }
            return dtable;
        }
    }
}